package com.sgb.kjwl.view.ui.activity.enterprise;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityAddNewQuoteResultBinding;

/**
 * Time:2021/7/13
 * Author:黄淋
 * Description:报价、选择报家单位结果
 */
public class AddNeedQuoteResultActivity extends AppActivity {
    private ActivityAddNewQuoteResultBinding mBinding;


    /**
     * @param context
     * @param isSuccess       是否提交成功
     * @param isChooseCompany 是否是选择报价单位
     */
    public static void start(Context context, boolean isSuccess, boolean isChooseCompany) {
        Intent intent = new Intent();
        intent.setClass(context, AddNeedQuoteResultActivity.class);
        intent.putExtra("isSuccess", isSuccess);
        intent.putExtra("isChooseCompany", isChooseCompany);
        context.startActivity(intent);
    }


    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_add_new_quote_result);

        boolean isSuccess = getIntent().getBooleanExtra("isSuccess", false);
        boolean isChooseCompany = getIntent().getBooleanExtra("isChooseCompany", false);
        if (isChooseCompany) {
            mBinding.ivUploadState.setImageResource(R.mipmap.authen_fail);
            mBinding.tvUploadState.setText("出了点状况，您表单提交失败了，\n请稍后重试");
            mBinding.tvUploadState.setTextColor(getResources().getColor(R.color.color_FF4B10));
        } else {
            if (isSuccess) {
                mBinding.ivUploadState.setImageResource(R.mipmap.authen_success);
                mBinding.tvUploadState.setText("您的报价提交成功");
                mBinding.tvUploadState.setTextColor(getResources().getColor(R.color.color_06C764));
            } else {
                mBinding.ivUploadState.setImageResource(R.mipmap.authen_fail);
                mBinding.tvUploadState.setText("出了点状况，您的报价提交失败了，\n请稍后重试");
                mBinding.tvUploadState.setTextColor(getResources().getColor(R.color.color_FF4B10));
            }
        }

        mBinding.tvBackToDetail.setOnClickListener(a -> {
            finish();
            handler.removeMessages(0);
        });
        handler.sendEmptyMessageDelayed(0, 1000);
    }

    private int time = 3;
    @SuppressLint("HandlerLeak")
    private final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            time--;
            if (time == 0) {
                finish();
                handler.removeMessages(0);
            }
            handler.sendEmptyMessageDelayed(0, 1000);
            mBinding.tvCountSecond.setText(time + "");
        }
    };
}
